import React, {PureComponent} from 'react';
import {ButtonComp, FileUploadComp, GlobalProvider} from 'jh-lib';

const requestObj = {
    request: () => (new Promise(resolve => {
        setTimeout(() => {
            resolve({status: 200, data: 'xx/xx'})
        }, 5000);
    }))
}

export default class Test extends  PureComponent {

    state={
        visible:false,
    };

    /**
     * 所有文件上传完成后的回调
     * @param files 上传完成的文件对象数组
     */
    onUploadDone({files}) {

    }

    onChangeUploaded(uploadedFiles, allFiles) {
        console.log('onChangeUploaded', uploadedFiles, allFiles);
    }

    render(){
        return (
            <>
                <GlobalProvider request={requestObj}>
                    <FileUploadComp
                        isModal={true}
                        visible={this.state.visible}
                        onUploadDone={this.onUploadDone.bind(this)}
                        onChangeUploaded={this.onChangeUploaded.bind(this)}
                        hideModal={()=>{this.setState({visible:false})}}
                        autoHide={false}
                        accept={'.json,.jpg,.jpeg,.png'}
                        needDir={false}
                    />
                    <ButtonComp onClick={()=>{this.setState({visible:true})}}>
                        上传
                    </ButtonComp>
                </GlobalProvider>
            </>)
    }
}
